// https://codepen.io/jiazengp/pen/dyWvxem

@charset "utf-8";

$namespace: loading;

$loading-img-height: 62.5px !default;
$loading-img-width: 500px !default;

$mobile: 719px !default;

$text-loading-animation-delay: 0.15s !default;
$text-loading-animation-item-size: 5px !default;
$text-loading-animation-rotate-size: 50px !default;

:root {
  --#{$namespace}-background-color: #fff;
  --#{$namespace}-font-color: rgba(0, 0, 0, 0.7);
  --#{$namespace}-loadingbar-background-color: #f5f5f5;
  --#{$namespace}-loadingbar-prospect-color: #666666;
}

html.dark {
  --#{$namespace}-background-color: #161d22;
  --#{$namespace}-font-color: rgba(240, 246, 252, 0.8);
  --#{$namespace}-loadingbar-background-color: #2c2b30;
  --#{$namespace}-loadingbar-prospect-color: #ece5d8;
}

html {
  --#{$namespace}-background-color: #fff;
  --#{$namespace}-font-color: rgba(0, 0, 0, 0.7);
  --#{$namespace}-loadingbar-background-color: #f5f5f5;
  --#{$namespace}-loadingbar-prospect-color: #666666;
}

@mixin img-color($color, $top: 500px) {
  position: absolute;
  left: 0;
  top: $top;
  filter: drop-shadow(0 #{-$top} 0 $color);
}

.wrapper {
  position: position;
  width: 100vw;
  height: 100%;
  overflow-x: hidden;
  user-select: none;
  background-color: var(--#{$namespace}-background-color);
  transition: background 0.5s cubic-bezier(0.28, 0.11, 0.32, 1);
  .loading {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99999;
    width: 100vw;
    height: 100vh;
    background-color: var(--#{$namespace}-background-color);
    opacity: 1;
    overflow-y: hidden;
    transition: all 0.3s;
    @supports (filter: drop-shadow(0 0 0 #fff)) {
      .loading-default {
        position: absolute;
        left: 50%;
        top: 50%;
        width: $loading-img-width;
        height: $loading-img-height;
        transform: translate(-50%, -50%) scale(0.8);
        transition: all 0.5s;
        overflow: hidden;

        img {
          @include img-color(var(--#{$namespace}-loadingbar-background-color));
        }

        &::after {
          content: '';
          @include img-color(var(--#{$namespace}-loadingbar-prospect-color));
          width: $loading-img-width;
          height: $loading-img-height;
          background: url('../../imgs/loading-bar.png') no-repeat left 100%;
          background-size: $loading-img-width $loading-img-height;
          background-position-x: 0;
        }
      }

      .loading-mobile {
        display: none;
      }
    }

    @supports not (filter: drop-shadow(0 0 0 #fff)) {
      .loading-default {
        display: none;
      }
      .loading-mobile {
        display: inline-block;
      }
    }

    @media screen and (max-width: $mobile) {
      .loading-default {
        display: none;
      }

      @media screen and (orientation: landscape) {
        .loading-default {
          display: block !important;
          transform: translate(-50%, -50%) scale(0.7) !important;
        }

        .loading-mobile {
          display: none !important;
        }
      }

      .loading-mobile {
        display: inline-block;
        position: absolute;
        width: 150px;
        height: auto;
        left: 50%;
        top: 50%;
        text-align: center;
        transform: translate(-50%, -50%) scale(1.2);

        .rotate {
          position: relative;
          width: $text-loading-animation-rotate-size;
          height: $text-loading-animation-rotate-size;
          margin: 0 $text-loading-animation-rotate-size;
          padding: 0;
          background-color: transparent;
          transform: scale(1.2);
          li {
            position: absolute;
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: flex-end;
            animation: rotating 4s linear infinite;
            @for $i from 1 through 5 {
              &:nth-child(#{$i}) {
                animation-delay: $text-loading-animation-delay * $i;
              }
            }
            &::after {
              content: '';
              display: block;
              width: $text-loading-animation-item-size;
              height: $text-loading-animation-item-size;
              border-radius: 50%;
              background-color: rgb(214, 213, 213);
            }
          }
        }

        h2 {
          margin-top: 80px;
          font-size: 1.3125em;
          color: var(--#{$namespace}-font-color);

          dot {
            display: inline-block;
            height: 1em;
            line-height: 1;
            text-align: left;
            vertical-align: -0.25ex;
            overflow: hidden;
            &::before {
              display: block;
              content: '...\A..\A.';
              white-space: pre-wrap;
              animation: dot 2s infinite step-start both;
            }
          }
        }
      }
    }
  }
}

@keyframes dot {
  33% {
    transform: translateY(-2em);
  }
  66% {
    transform: translateY(-1em);
  }
}

@keyframes rotating {
  // 移动端loading动画逻辑
  75% {
    transform: rotate(600deg);
  }

  79% {
    transform: rotate(720deg);
    opacity: 1;
  }

  80% {
    transform: rotate(720deg);
    opacity: 0;
  }

  100% {
    transform: rotate(810deg);
    opacity: 0;
  }
}

@keyframes loading-bar {
  0% {
    width: 0px;
    background-size: $loading-img-width $loading-img-height;
  }

  16.6% {
  }

  33.2% {
  }

  49.8% {
  }

  66.4% {
  }

  83% {
  }

  100% {
    width: $loading-img-width;
  }
}
